import VueRouter from 'vue-router'

import Home from '@/views/Home'
import AllProducts from '@/views/AllProducts'
import Cart from '@/views/Cart'
import User from '@/views/User'

const routes=[
    {
        path:'/home',
        component:Home
    },
    {
        path:'/allproducts',
        component:AllProducts
    },
    {
        path:'/cart',
        component:Cart
    },
    {
        path:'/user',
        component:User
    },
    {
        path:'/',
        redirect: '/home',//设置默认指向的路径
    },
]

// 禁止跳转到原路由时打印报错信息
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
const VueRouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (to) {
  return VueRouterReplace.call(this, to).catch(err => err)
}

export default new VueRouter({
    routes
})